feat(tilelib): materialize PTODSL in process - #1103
Merged
Merged
Conversation
mouliangyu
force-pushed
the
codex/embedded-ptodsl-context
branch
from
August 4, 2026 05:43
279b47f to
7b080c2
Compare
Zhendong404
approved these changes
Aug 7, 2026
mouliangyu
marked this pull request as ready for review
August 7, 2026 09:15
A5 板测失败
失败用例
|
A3 板测完成(有跳过)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
TileOp 展开此前通过独立 Python daemon 完成 PTODSL 模板选择和 MLIR 生成,需要维护子进程、Unix socket、JSON wire protocol、临时文件以及 MLIR 文本打印/解析。主线移除 legacy TileLang backend 后,这套隔离层只剩 PTODSL 使用,也阻碍了模板实例化直接复用当前编译的 MLIRContext。
主要变更
TileLibServiceC++ 边界:候选查询只传 specialization metadata,模板实例化接收当前MLIRContext并返回同 context 下的 source module handle。_core模块初始化时安装进程级唯一TileLibRuntimeservice;runtime 不绑定某个 compilation context,也不在 pass 中保存 Python 对象。_core.main创建独立 PythonContextowner,nativePTOASContext在该调用的动态范围内借用同一个底层MLIRContext;连续多次编译共享 runtime,但 context 相互独立。InsertTemplateAttributes/ExpandTileOp恢复为 TableGen 标准注册、默认可构造的 pass。pass 从getContext()获取当前 context,并从进程级 runtime 取得 service,因此可继续留在连续 pass pipeline,也支持 targeted IR instrumentation。isTileLibExpandableOp过滤:没有可展开 TileOp 时 pass 直接返回,不要求 runtime。.mlir_text()与 compiler materialization API 分开:前者创建 fresh context,后者必须调用build_module_in_context(context)。生命周期与边界
Contextowner 负责底层MLIRContext生命周期;PTOASContext和 pass 只借用当前 compilation context。TileLibRuntime只管理 process-wide service,module teardown 时通过 capsule 注销,避免跨 DSO/CPython 生命周期留下悬挂全局对象。_core.main。并发 driver invocation 仍受 LLVM 全局 command-line state 限制,不在本 PR 承诺范围内。验证
cmake --build .work/tileop-embedded-python-study/build --target PTOASPythonPackage -j4ctest --test-dir .work/tileop-embedded-python-study/build --output-on-failure -L PTODSL -j4:25/25 通过llvm-lit -sv:以下 4 个 TileOp/VPTO 用例全部通过expand_tile_op_ptodsl_tadd.ptoexpand_tile_op_ptodsl_tsub.ptoexpand_tile_op_ptodsl_view_stride_cache.ptovpto_pipeline_vmi_after_tileop_expand.ptotest_ptoas_runtime.py,验证同一进程连续两次_core.main使用不同 compilation context 且共享 process runtime,并均完成 TileOp 展开。python3 -m py_compile、git diff --check通过。构建和测试使用 LLVM/MLIR 21.1.8。